package org.mycub.server.mock.trams.factories;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

import org.mycub.server.mock.trams.models.TramStation;

public class TramStationsFactory {

	public static int MAX_STATIONS = 20;
	public static int MAX_STRING_LENGTH = 20;

	public TramStationsFactory() {

	}

	public List<TramStation> createMockStations(double lon, double lat,
			double radius) {

		Random rand = new Random();
		int nb = rand.nextInt(MAX_STATIONS);
		List<TramStation> list = new ArrayList<TramStation>();

		for (int i = 0; i < nb; i++) {
			TramStation ts = new TramStation();

			ts.setId(i);
			ts.setLine(generateRandomLine());
			ts.setLongitude(lon + radius * rand.nextDouble());
			ts.setLatitude(lat + radius * rand.nextDouble());
			ts.setAddress(generateRandomString());
			ts.setName(generateRandomString());
			ts.setPayment(rand.nextInt(2) == 1);
			ts.setSpecial(rand.nextInt(2) == 1);

			list.add(ts);
		}

		return list;
	}

	public String generateRandomString() {
		char[] chars = "abcdefghijklmnopqrstuvwxyz".toCharArray();
		StringBuilder sb = new StringBuilder();
		Random random = new Random();
		int stringLength = random.nextInt(MAX_STRING_LENGTH);
		for (int i = 0; i < stringLength; i++) {
			char c = chars[random.nextInt(chars.length)];
			sb.append(c);
		}
		return sb.toString();
	}
	
	public char generateRandomLine(){
		char[] chars = "ABCD".toCharArray();
		Random random = new Random();
		return chars[random.nextInt(4)];
	}
}
